import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { fileURLToPath, URL } from 'node:url'
// 饿了没ui自动化引入插件
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

export default defineConfig({
  plugins: [
    vue(),
    // 饿了没ui配置插件
    AutoImport({
      resolvers: [ElementPlusResolver({importStyle:'sass'})],
    }),
    Components({
      resolvers: [ElementPlusResolver({importStyle:'sass'})],
    }),
  ],
  // server: {
  //   host: true, // 可以以IP访问
  //   port: 8080, // 端口
  //   cors: true, // 允许跨域
  //   proxy: {
  //     '/api': {
  //       // 这里配置真实的后端环境地址
  //       target: 'http://localhost:3000',
  //       changeOrigin: true,
  //       rewrite: (path) => path.replace('/api/', '/'),
  //     },
  //   },
  // },
  build: {
    // 消除打包大小超过500kb警告
    chunkSizeWarningLimit: 2000,
    // 在生产环境移除console.log
    terserOptions: {
      compress: {
        drop_console: false,
        pure_funcs: ['console.log', 'console.info'],
        drop_debugger: true,
      },
    },
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `
             @use "@/styles/themecolor" as *;
             @use "@/styles/element/index" as *;
          `,
      },
    },
  },
  resolve: {
    // 实际的路径转换 将@ 转换为./src
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
})
